package com.nidu.demo.notify.executor.query;

import com.alibaba.cola.dto.MultiResponse;
import com.nidu.demo.notify.convertor.NotifyTemplateConvertor;
import com.nidu.demo.notify.convertor.NotifyTemplateCriteriaConvertor;
import com.nidu.demo.notify.dto.NotifyTemplateCO;
import com.nidu.demo.notify.dto.NotifyTemplateListQry;
import com.nidu.demo.notify.gateway.NotifyTemplateGateway;
import com.nidu.demo.notify.model.NotifyTemplate;
import com.nidu.demo.notify.model.NotifyTemplateCriteria;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 站内信消息模板列表查询执行器
 *
 * @author auto
 */
@Component
@RequiredArgsConstructor
public class NotifyTemplateListQryExe {

    private final NotifyTemplateCriteriaConvertor criteriaConvertor;
    private final NotifyTemplateGateway gateway;
    private final NotifyTemplateConvertor convertor;

    public MultiResponse<NotifyTemplateCO> execute(NotifyTemplateListQry qry) {
        NotifyTemplateCriteria criteria = criteriaConvertor.toDataObject(qry);
        List<NotifyTemplate> templates = gateway.listByCondition(criteria);
        List<NotifyTemplateCO> templateCOS = convertor.toClientObjects(templates);
        return MultiResponse.of(templateCOS);
    }
}
